home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
fix_fat.zip
/
FAT.TXT
< prev
next >
Wrap
Text File
|
1985-06-15
|
8KB
|
147 lines
This library contains three small utilities for recovering from
several possible floppy disk problems. As far as I know, they will
probably only work on dual-sided, dual-density MS-DOS disks. All IO is
done with MS-DOS function calls, so the routines are probably pretty
portable. My only experience with MS-DOS is with version 2.1, so
I'm afraid these routines may not work with earlier (or later) versions
of the operating system. However, I have included the DeSmet C sources
for the routines, so you may be able to generalize the routines after
reading the tutorial below.
I have found these routines useful for recovering from two types of
"lost data" problems on my diskettes. The first type of situation is
when a file is mistakenly deleted from the disk. A more complicated
situation arises when the directory or file allocation tables somehow
become corrupted (in my case this happened when I mistakenly switched
diskettes while files were still open).
If you should encounter one of the above problems yourself, DON'T
PANIC!!!! Immediately STOP WHATEVER YOU ARE DOING and think carefully
about the best way to recover. It is important not to write anything
else on the diskette as it may overwrite data you are trying to save.
Make a backup copy of the damaged diskette with the DISKCOPY command
before doing anything else, as these procedures are very powerful, and
can easily compound your problems if you make a mistake.
This document is divided into two parts. The first section is a
tutorial which is based on Appendix C of the PC-DOS reference manual.
It assumes less technical expertise on your part than Appendix C does
however. It is followed by detailed descriptions of of the three
utilities included in this package: FAT, PFAT, and TOSECT.
Tutorial
--------
In this section, I will give you enough background in how DOS stores
your information on diskettes to enable to use the utilities in this
package to recover them. I'll assume that you have some knowledge of
the MS-DOS operating system, but that you are not necessarily a computer
expert. The first part of this tutorial deals with the general
organization of DOS files on disk. It is followed by sections on the
disk directories and file allocation tables. Two important topics in
restoring the data are treated in appendices: the DEBUG program, and
hexadecimal notation. If you are unfamiliar with either of these
topics, I would advise reading the appendices before proceeding with the
rest of this section.
NOTE: In the following sections, I will often use Hexadecimal notation
for numbers. A hexadecimal number will be followed by a captital X.
More details about hexadecimal notation can be found in appendix B.
Some examples of hexadecimal numbers are given below:
Hexadecimal Number Decimal Number
------------------ --------------
5X 5
10X 16
33X 51
200X 512
DISK ORGANIZATION
This section describes the organization of double sided double
density MS-DOS disks. If your diskettes were formatted with DOS 2.0,
they will be formatted as described below. Trying to use these
utilities with other versions of DOS or other diskette formats will
produce unpredictable results.
The floppy disks used by DOS to store data are organized into units
called sectors. Each sector on a DOS diskette can hold 512 bytes
of information (a byte is the amount of computer storage necessary
to hold one character of data). The sectors are organized into
larger units called clusters and tracks. A cluster is two
consecutive sectors on the disk. A track consists of a group of 9
sectors, but you won't have to worry about them since we will only
be dealing with sectors and clusters.
The first few sectors on each diskettes have special purposes
assigned to them. We will refer to the sectors by their logical sector
numbers (this is the same scheme used by the DOS DEBUG program). The
first logical sector (number 0X) is the boot record. The next four
sectors (logical sectors 1X-4X) are for two copies of the disk's File
Allocation Table (FAT). These tell the operating system where the
consecutive pieces of a file arer located on the disk. The FAT will be
explained in gory detail in a later section. The FAT's are followed by
the Root Directory for the diskette (sectors 5X - BX ). This contains information about
all of the files stored in the diskette's root directory. It also
contains information about the diskettes subdirectories, which are
treated by the operating system as just a special kind of file.
The logical sectors from CX to the end of the diskette are the
diskette's data area. They contain the actual information you have
stored in files. There are several types of files which you might have
in your data area. Some of them are easier to recover than others. The
easiest type of files to piece back together are ASCII files. These are
basically normal text files that can be typed on the terminal. When
sectors from these files are examined with the DEBUG utility, you can
see the text that is stored in these files by useing the d command. The
text will appear as strings of characters on the left hand side of the
display. These are the easiest kinds of files to recover.
Another type of file is the kind I call "almost ASCII files". These
files are produced by word processing programs, data base programs, and
many interpreters (such as BASIC). They consist of mostly ASCII
characters that can also be displayed with the DEBUG d command. The
things that makes them a little more complicated to recover than pure
ASCII files is that they also contain other information besides these
text characters (such as word processing codes for bold face, italics,
and underlining). While these files are harder to restore than the pure
ASCII files, they usually contain enough ASCII characters to be able to
piece them back together if you are familiar with the file's contents.
The hardest kinds of files to recover are binary files. These
are files such as programs ( COM and EXE files ) and unformatted data
files produced by some programming languages, data base programs, and
spreadsheet programs. I wouldn't suggest even attempting to restore
these files unless you are an extremely competent assembly language
programmer and very familiar with the files contents. There is one
exception to the above situation however which will be discussed in more
detail in the FAT section. This occurs when the file is suspected to
occupy consecutive clusters on the disk.
Another class of files in the data area are subdirectories. They
are stored in the same way as ordinary files except for a special
notation that is made in their parent directory. The format of these
files is the same as that of the root directory. I will explain more
about them in the directory section below.
In summary, the smallest unit on the diskette with which we will
work is called a byte (the amount of storage needed for one character).
The next largest unit is a sector which consists of 512 (200X) bytes.
The sectors are numbered starting with 0. Two consecutive sectors make
up a cluster which has 400X bytes. The first twelve sectors on the
diskette (sectors 0X to BX) contain special information that tell the
operating system where the file information is physically located on the
disk. The rest of the sectors contain the actual file data.
DIRECTORIES
The directories tell the operating system essential information
about each file on the disk. The easiest directory to find is the root
directory stored in blocks 5X to BX. The directory consists of 112
32-byte entries. If you only want to undelete a file you need to know
about the first byte in the file name part of the entry and how to find
where the beginning of the file is on the disk. If the entire directory
was destroyed, you'll need to